// 发送请求
import { list } from "@/api";

// 常量
const LIST = "menu_content";

const actions = {
	async [LIST]({ commit }) {
		let result = await list();
		if (result.code === 200) {
			commit(LIST, result.data);
			return "ok";
		} else {
			return Promise.reject(new Error("获取标签数据失败！"));
		}
	},
	// 重置tagsList标签
	resetList({ commit }) {
		console.log("重置");
		commit("resetList");
	},
};

const mutations = {
	[LIST](state, value) {
		state[LIST] = value;
	},
	resetList(state) {
		state.tagsList = [
			{ id: 0, title: "前端", content: [] },
			{ id: 1, title: "后端", content: [] },
			{ id: 2, title: "框架", content: [] },
			{ id: 3, title: "其他", content: [] },
		];
	},
};

const state = {
	[LIST]: [],
	// 选择的tags标签数据
	tagsList: [
		{ id: 0, title: "前端", content: [] },
		{ id: 1, title: "后端", content: [] },
		{ id: 2, title: "框架", content: [] },
		{ id: 3, title: "其他", content: [] },
	],
};

export default {
	//开启命名空间,这个必须要开，不然报错
	namespaced: true,
	actions,
	mutations,
	state,
};
